//
//  ViewController.m
//  Play-UIStackView
//
//  Created by 中创 on 2019/6/12.
//  Copyright © 2019 中创慧谷. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()


@property (nonatomic, strong) UIStackView * verticalStackView;
@property (nonatomic, strong) UIStackView * horizontalStackView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor greenColor];
    
    [self.view addSubview:self.horizontalStackView];
    self.horizontalStackView.frame = CGRectMake(10, 100, self.view.frame.size.width-20, 100);
    return;
    [self.view addSubview:self.verticalStackView];
    self.verticalStackView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UILabel * lbl = [self textLbl];
    
    [self.horizontalStackView addArrangedSubview:lbl];
//    [self.horizontalStackView addSubview:lbl];
    [UIView animateWithDuration:1 animations:^{
        [self.horizontalStackView layoutIfNeeded];
    }];
    
    return;
    [self.verticalStackView addArrangedSubview:lbl];
    [UIView animateWithDuration:1 animations:^{
//        [self.verticalStackView layoutIfNeeded];
    }];
}

- (UILabel *)textLbl{
    UILabel * lbl = [UILabel new];
    lbl.backgroundColor = [UIColor redColor];
    lbl.text = @"文字";
    return lbl;
}

#pragma mark --- 懒加载
- (UIStackView *)verticalStackView{
    if (_verticalStackView == nil) {
        _verticalStackView = [UIStackView new];
        _verticalStackView.axis = UILayoutConstraintAxisVertical;
        _verticalStackView.distribution = UIStackViewDistributionFillEqually;
        _verticalStackView.spacing = 10;
        _verticalStackView.alignment = UIStackViewAlignmentFill;
        _verticalStackView.backgroundColor = [UIColor yellowColor];
    }
    return _verticalStackView;
}
- (UIStackView *)horizontalStackView{
    if (_horizontalStackView == nil) {
        _horizontalStackView = [UIStackView new];
        _horizontalStackView.axis = UILayoutConstraintAxisHorizontal;
        _horizontalStackView.distribution = UIStackViewDistributionFillEqually;
        _horizontalStackView.spacing = 10;
        _horizontalStackView.alignment = UIStackViewAlignmentFill;
        _horizontalStackView.backgroundColor = [UIColor yellowColor];
    }
    return _horizontalStackView;
}

@end
